<template>
	<view class="index">
		
		<!-- #ifdef APP-PLUS || MP-WEIXIN -->
		<view class="press-tips">点击输入行上边的名称可语音输入</view>
		
		<!-- #endif -->
		
		
		<view class="uni-list">
			<label-input v-for="(item, index) of (data.bottom && data.bottom.value)" ref="mpvuePicker" :key="index" :child_data="item" :alldata="data.common.value" :inkey="index" @input_value="inputValue"></label-input>
		</view>
		
		<view class="btn-row uni-flex">
			<button type="primary" class="primary uni-flex-item" style="margin-right: 10upx;" @tap="save">保存</button>
		</view>
	</view>
</template>

<script>
	
	import net from '../../net.js';
	import service from '../../service.js';
	import utils from '../../common/utils.js';
	import labelInput from '../../components/label-input.vue';
	import uploaddata from '../../uploaddata.js';
	import uniIcons from "@/components/uni-icons/uni-icons.vue"
	
	export default {
		components: {
			labelInput,
			uniIcons
		},
		data() {
			return{
				data: {
					bottom: {}
				},
				codeId: 0,
				tableId: 0,
			}
			
		},
		onLoad(res) {
			this.codeId = res.codeId;
			this.tableId = res.tableId;
			let data = service.getTaskDetailItem(this.codeId, this.tableId);
			this.data.bottom = {};
		
			Object.assign(this.data, data);
			console.log(this.data);
		},
		onReady() {
			this.initItem();
			console.log('onReady');
		},
		methods: {
			//组件传值事件,input组件传出的新值
			inputValue(newdata,key){
				console.log(newdata,key);
				this.data.bottom.value[key]=newdata;
			},
			initItem(){
				setTimeout(()=>{
					this.$refs.mpvuePicker && this.$refs.mpvuePicker.forEach((item, index)=>{
						item.init();
					});
				}, 0);
			},
			save(){
				try{
					uni.showLoading({title: '', mask: true});
					service.setTaskDetailItem(this.codeId, this.tableId, this.data, 'bottom');
					uni.hideLoading();
					uni.showToast({icon: 'none', title: '保存成功'});
					utils.exeMainCallBack({}, '上传');
					setTimeout(()=>{
						uni.navigateBack({delta: 1});
					}, 500);
				}catch(e){
					uni.hideLoading();
					uni.showToast({icon: 'none', title: '保存失败'});
				}
			}
		},
	}
</script>

<style>
	.index{
		width: 100%;
	}
	.hide {
		display: none;
	}
	
	.uni-list {
		margin: 10upx 0 60upx 0;
	}
	
	.uni-list-cell:after {
		left: 0;
	}
	
	.uni-list-cell {
		padding: 0 20upx;
		min-height: 90upx;
		color: #666;
	}
	
	.uni-list-cell.con-list {
		flex-wrap: wrap;
	}
	
	.uni-list-cell.con-list text {
		flex: 0 0 100%;
		font-size: 32upx;
	}
	
	.uni-list-cell-divider ~ .uni-list-cell {
		padding-left: 50upx;
		min-height: 70upx;
	}
	
	.uni-list-cell.no-left {
		padding-left: 20upx;
	}
	
</style>

